/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.example.evaluation;

import org.nudt.jCloud.evaluation.Evaluation;
import org.nudt.jCloud.infrastructure.HomegeneousCluster;
import org.nudt.jCloud.infrastructure.SlotType;
import org.nudt.jCloud.jobScheduler.AFCFSGangScheduler;
import org.nudt.jCloud.jobScheduler.FCFSGangScheduler;
import org.nudt.jCloud.jobScheduler.JobScheduler;
import org.nudt.jCloud.resourceManager.GeneralReservationRM;
import org.nudt.jCloud.resourceManager.ResManager;
import org.nudt.jCloud.resourceScaler.ConstantScaler;
import org.nudt.jCloud.resourceScaler.ResourceScaler;
import org.nudt.jCloud.resourceScaler.ThresholdScaler;
import org.nudt.jCloud.simulation.CloudSchedSIM;
import org.nudt.jCloud.simulation.SIMTag;
import org.nudt.jCloud.simulation.User;
import org.nudt.jCloud.simulation.UserBroker;
import org.nudt.jCloud.workload.GangWLGen;
import org.nudt.jCloud.workload.Workload;
import org.nudt.jCloud.workload.WorkloadGenerator;

public class RS_Example {
	public static void main(String[] args){
		CloudSchedSIM.init("RSExample_Constant");
		HomegeneousCluster homeCluster = new HomegeneousCluster(20, 1000, 4, 4000, 1000, 200000);
		ResManager reservationRM = new GeneralReservationRM("ReservationRM", homeCluster);
		UserBroker userBroker1 = new UserBroker("UserBroker", SIMTag.RM_MODE_R);
		SlotType slotType = new SlotType(1, 1000, 250, 0);
		WorkloadGenerator wlGen = new GangWLGen(5000, 40, 50, 0.4, 40, slotType);
		Workload wl = wlGen.generate(0);
		JobScheduler jobScheduler1 = new FCFSGangScheduler("FCFS_Gang");
		ResourceScaler resourceScaler1 = new ConstantScaler(slotType, 50);
		userBroker1.init(jobScheduler1, resourceScaler1);
		User user = new User("user", wl);
		userBroker1.addUser(user);
		CloudSchedSIM.addRM(reservationRM);
		CloudSchedSIM.addUserBroker(userBroker1);
		CloudSchedSIM.startSimulation();
		
		CloudSchedSIM.reset("RSExample_Threshold");
		reservationRM.reset();
		user.reset();
		ResourceScaler resourceScaler2 = new ThresholdScaler(8, 0.5);
		userBroker1 = new UserBroker("UserBroker", SIMTag.RM_MODE_R);
		JobScheduler jobScheduler2 = new AFCFSGangScheduler("AFCFS_Gang");
		userBroker1.init(jobScheduler2, resourceScaler2);
		userBroker1.addUser(user);
		CloudSchedSIM.addRM(reservationRM);
		CloudSchedSIM.addUserBroker(userBroker1);
		CloudSchedSIM.startSimulation();
		
		Evaluation.avgWaitTime("RSExample_Constant", "user");
		Evaluation.avgWaitTime("RSExample_Threshold", "user");
		
		System.out.println();
		
		Evaluation.avgWeightedWaitTime("RSExample_Constant", "user");
		Evaluation.avgWeightedWaitTime("RSExample_Threshold", "user");
		
		System.out.println();
		
		Evaluation.slotHour("RSExample_Constant", "userBroker");
		Evaluation.slotHour("RSExample_Threshold", "userBroker");
		
	}

}
